/**
 * @author Archana Sethuraman
 * @date 10/27/2011
 * @description Controller for the Outcome Form page. This retrives the list of implants by calling the OrderedImplant class.
 * It also performs the update when Save, Save and Start new Implant buttons are clicked.
 */

public with sharing class MM_ImplantOutcomeController{

   private final Patient__c patient;
   private List<MM_OrderedImplant> implantList;
   
   //Retrives the list of implants for a particular patient from the MM_OrderedImplant class
   public MM_ImplantOutcomeController(ApexPages.StandardController parentController) {
      patient = (Patient__c)parentController.getRecord();
      implantList = MM_OrderedImplant.getPatientImplants(patient.Id, 
         'Implant_Date__c,Outcome_Date__c,Transplanted__c,Explanted_Recovery__c,' +
         'Explanted_Other__c,Pump_Exchange__c,Death__c,Surgeon__c');
   }
   
   
   
   
   public List<MM_OrderedImplant> implants {
      get { return implantList; }
   }

  
    
   /**
    * @author Archana Sethuraman
    * @description Method to Save the updated Implant records.
    * Calls the updatePatientImplants() function in the MM_OrderedImplant class to update the list of implants 
    * @return the Same page
    */
   public PageReference save() {
 
      MM_OrderedImplant.updatePatientImplants(implants);
      PageReference nextPage;
      {
      	
         nextPage = Page.MM_ImplantOutcome;
         nextPage.getParameters().put('id', patient.Id);
         nextPage.setRedirect(true);
      }
      return nextPage; 
   }

	/**
    * @author Archana Sethuraman
    * @description Method to Save the updated Implant records and redirect to the create new Implant page.
    * Calls the updatePatientImplants() function in the MM_OrderedImplant class to update the list of implants 
    * TODO modify the redirect page
    * @return to the create new Implant page
    */
  public PageReference saveAndStartNewImplant() {
   	
      MM_OrderedImplant.updatePatientImplants(implants);
      	 
      PageReference nextPage;
      {
      		//need to change page reference when the corresp pages are created
         nextPage = Page.MM_ImplantOutcome;
         nextPage.getParameters().put('id', patient.Id);
         nextPage.setRedirect(true);
      }
      return nextPage; 
   }
   
   /**
    * @author Archana Sethuraman
    * @description Cancel and redirect to some other page
    * TODO modify the redirect page
    * @return newPage
    */
   public PageReference cancel() {
   	//need to change page reference when the corresp pages are created
      PageReference nextPage = Page.MM_ImplantOutcome;
      nextPage.getParameters().put('id', patient.Id);
      nextPage.setRedirect(true);
      return nextPage;
   }
}